package com.zmm.weblog.common.domain.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zmm.weblog.common.domain.dos.CategoryDo;
import com.zmm.weblog.common.domain.dos.TagDo;
import com.zmm.weblog.common.utils.PageResponse;
import com.zmm.weblog.common.utils.Response;
import org.apache.ibatis.annotations.Mapper;

import java.time.LocalDate;
import java.util.List;
import java.util.Objects;

/**
 * @Author:福禄寿
 * @Date:2024/4/30 下午4:04
 * @Des:weblog-springboot
 **/
@Mapper
public interface TagMapper extends BaseMapper<TagDo> {

    default Page<TagDo> selectPageList(long current, long size, String name,LocalDate startDate,LocalDate endDate){

        Page<TagDo> tagDoPage = new Page<>(current, size);

        LambdaQueryWrapper<TagDo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(Objects.nonNull(name), TagDo::getName, name)
                .ge(Objects.nonNull(startDate), TagDo::getCreateTime, startDate)
                .le(Objects.nonNull(endDate), TagDo::getCreateTime, endDate)
                .orderByDesc(TagDo::getCreateTime);
        return selectPage(tagDoPage, queryWrapper);
    }

    default List<TagDo> selectByName(String name){
        LambdaQueryWrapper<TagDo> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(TagDo::getName, name.trim()).orderByDesc(TagDo::getCreateTime);
        return selectList(wrapper);
    };

    /**
     * 根据标签id批量查询
     * @param tagIds
     * @return
     */
    default List<TagDo> selectByIds(List<Long> tagIds){
        return selectList(new LambdaQueryWrapper<TagDo>().in(TagDo::getId, tagIds));
    }


}

